package main

import (
	_ "blog/controller"
	"crypto/md5"
	"fmt"
	"net/http"
)

/*
程序入口
*/
func main() {
	http.HandleFunc("/", receiveClientRequest)
	if err := http.ListenAndServe("127.0.0.1:8080", nil); err != nil {
		fmt.Println("http start failed, err:", err)
		return
	}

	//test()
}

func test() {
	str := "admin123"
	data := []byte(str)
	has := md5.Sum(data)
	md5str1 := fmt.Sprintf("%x", has) //将[]byte转成16进制
	fmt.Println("------")
	fmt.Println(md5str1)
}

func receiveClientRequest(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")             //允许访问所有域
	w.Header().Add("Access-Control-Allow-Headers", "Content-Type") //header的类型
	w.Header().Set("content-type", "application/json")             //返回数据格式是json
}
